package it.unisa.unibox.gestioneAutenticazione;

import it.unisa.unibox.facade.IFacadeAutenticazione;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public static ServletContext servletContext;
	public static IFacadeAutenticazione facade;

	@Override
	public void init(ServletConfig config) throws ServletException {
		try {
			super.init(config);			
			servletContext = getServletConfig().getServletContext();
		} 

		catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession();
			session.invalidate();	
			response.setContentType("text/html");
			response.setHeader("Cache-Control",	"no-store, no-cache, must-revalidate");
			PrintWriter out;
			out = response.getWriter();
			out.write("ok");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
